package cn.zt.controller;


import cn.zt.domain.dto.FlightDTO;
import cn.zt.domain.pojo.Result;
import cn.zt.domain.vo.FlightVO;
import cn.zt.domain.vo.OrderVO;
import cn.zt.service.ISelectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/select")
public class SelectController {

    @Resource
    private ISelectService selectService;

    /**
     * 查询航班
     * @param flightDTO
     * @return
     */
    @PostMapping("/flight")
    public Result selectFlight(@RequestBody FlightDTO flightDTO) {

        System.out.println("查询航班");
        System.out.println(flightDTO.getbDate() + " " + flightDTO.geteDate() +
                " " + flightDTO.getbDestination() + " " + flightDTO.geteDestination());
        List<FlightVO> flightList = selectService.selectFlightList(flightDTO);
        return Result.ok(flightList);
    }

    /**
     * 查询个人订单
     */
    @GetMapping("/order")
    public Result selectOrder(HttpServletRequest request) {
        Long userId = Long.valueOf(request.getHeader("Userid"));
        System.out.println("查询到用户" +  userId+ "的个人订单");

        List<OrderVO> orderList = selectService.selectOrderByUserId(userId);
        if (orderList == null){
            System.out.println("用户订单列表为空");
            return Result.fail("用户订单列表为空");
        }

//        for (OrderVO orderVO : orderList){
//            System.out.println(orderVO +
//                    orderVO.getEDestination() + orderVO.getDate() +
//                    orderVO.getFlightId());
//        }

        return Result.ok(orderList);
    }

}
